##################################################################################################################################
#
# Copyright (C) 2008-2014 Mind System Connection. Lda. Part of Daidze Software, created by Siqsuruq. All other rights reserved.
#
# Mind System Connection Webpage: www.msysc.org
# Daidze Software Page: www.daidze.com www.daidze.org
# E-mail: admin@msysc.org, siqsuruq@gmail.com
#
##################################################################################################################################

proc install_fonts {} {
	set files [glob [file join $::fonts *]]
	
	foreach f $files {
		# if {[string range $f 0 end-4] eq ".ttf"} {
			puts "FONT: $f"
			copy_font $f
		# }
	}
}

proc copy_font {font_name} {
	set token [twapi::open_process_token]
	set groups [twapi::get_token_groups_and_attrs $token]
	twapi::close_token $token
	if {[dict exists $groups S-1-5-32-544] && {enabled} in [dict get $groups S-1-5-32-544]} {
		
		set sys_root $::env(SystemRoot)
		set fonts_dir [file join $sys_root Fonts]
		file copy -force $font_name $fonts_dir
		edit_reg $font_name
		
	} else {
		puts "No admin rights"
	}
	
}

proc edit_reg {font_name} {
	set reg_path "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts"
	set font [string range $font_name 0 end-4]
	registry set $reg_path "$font (TrueType)" $font_name
}